package JHfstools;

import javax.swing.event.DocumentEvent;
import javax.swing.undo.CompoundEdit;
import javax.swing.undo.UndoableEdit;

	public class TypingEdit extends CompoundEdit {

	    public TypingEdit() {
	    }

	    public boolean addEdit(UndoableEdit edit) {
	        if(!(edit instanceof DocumentEvent))
	            return false;

	        if(0 == edits.size()) {
	            edits.add(edit);
	            return true;
	        } else if(Math.abs((((DocumentEvent)edits.lastElement()).getOffset() - 
	                ((DocumentEvent)edit).getOffset())) < 2) {
	            edits.add(edit);
	            return true;
	        }
	        return false;
	    }

	    public String getPresentationName() {
	        return "Typing";
	    }

	    public String getUndoPresentationName() {
	        return "Undo Typing";
	    }

	    public String getRedoPresentationName() {
	        return "Redo Typing";
	    }

	    public boolean canUndo() {
	        return true;
	    }

	    public boolean canRedo() {
	        return true;
	    }
	}
